package club.banyuan;

import java.util.*;

public class Class {

    private Set<Student> students = new HashSet<>();

    public void addMultipleData(Student[] students){
        this.students.addAll(Arrays.asList(students));
    }

    public void printInfo(){
        for (Student student : students) {
            System.out.println(student);
        }
    }

    public List<Student> sortAscendingById(){
        List<Student> list = new ArrayList<>(students);
        list.sort(Comparator.comparingInt(Student::getId));

//        list.sort(new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                return o1.getId()-o2.getId();
//            }
//        });
        return list;
    }

    public List<Student> sortDescendingByAge(){
        List<Student> list = new ArrayList<>(students);
        list.sort((o1, o2) -> o2.getAge() - o1.getAge());

//        list.sort(new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                return o2.getAge() - o1.getAge();
//            }
//        });
        return list;
    }

    public Set<Student> getStudents() {
        return students;
    }

    public void setStudents(Set<Student> students) {
        this.students = students;
    }
}
